Thread local storage is a computer programming method that supports global/static memory data that is unique to a thread, or task. Data within a static or global variable is typically located in the same memory location when referred to by threads from the same process. However, since each thread has its own stack, variables on the stack are local to the threads and reside in different memory locations. Typically, methods for supporting thread-local storage in a high-level language (e.g., C/C++) require tool chain support. In addition, this conventional method involves the usage of the _thread storage class attribute.
For instance, a global variable is declared as thread-local storage in C/C++ code as, “_thread int errno”, wherein errno is used for storing the error code related to functions from the Standard C library. The “errno” thread-local variable can be accessed in C/C++ code as:
if (errno == S_objLib_OBJ_TIMEOUT)  errno = S_eventLIB_TIMEOUT
Accordingly, it is common practice for code compilers that support multi-threaded applications to provide a separate instance of “errno” for each thread, in order to avoid different threads competing to read or update the value. Compilers often provide this facility in the form of extensions to the declaration syntax, such as “_thread” annotations on static variable declarations.